package com.hopu.shop.controller;

import com.alibaba.fastjson.JSON;
import com.feng.common.controller.CommonController;
import com.feng.common.util.Result;
import com.feng.common.util.ResultPage;
import com.hopu.shop.server.ShopInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collections;
import java.util.Map;

@Controller
@RequestMapping("shopInfo")
public class ShopInfoController extends CommonController {

    @Autowired
    ShopInfoService shopInfoService;

    @RequestMapping("/query")
    @ResponseBody
    public String shopInfo_query(@RequestParam Map map) throws Exception {
        Result result = new Result();
        result.setCode("0");

//        result.setData(shopInfoService.query(map));
        //分页
        String page = map.get("page").toString();
        String limit = map.get("limit").toString();
        page = (Integer.valueOf(page)-1)*Integer.valueOf(limit)+"";
        map.put("page",page);

        System.out.println("map===="+map);
        result.setCode("0");
        result.setData(shopInfoService.query(map));
        result.setCount(shopInfoService.inofcount(map).get("count")+"");


        return JSON.toJSONString(result);
    }


    /**
     * 修改
     * @param map
     * @return
     */
    @RequestMapping("/upd")
    @ResponseBody
    public String upd(@RequestParam Map map) throws Exception {
        System.out.println("mao1="+map);
        Result result = new Result();
        result.setCode("1");
        result.setData(Collections.singletonList(shopInfoService.upd(map)));
        return JSON.toJSONString(result);


    }

    /**
     * 新增
     * @param map
     * @return
     * @throws Exception
     */
    @RequestMapping("/sava")
    @ResponseBody
    public String sava(@RequestParam Map map)throws Exception{
        System.out.println("进入新增的方法");
        System.out.println("map="+map);
        Result result = new Result();
        result.setCode("1");
        result.setData(Collections.singletonList(shopInfoService.sava(map)));
        result.setShop_info_id(map.get("shop_info_id"));

        return JSON .toJSONString(result);
    }

    /**
     * 删除
     */

    @RequestMapping("/del")
    @ResponseBody
    public String del(@RequestParam Map map)throws Exception{
        System.out.println("进入了删除的方法");
        System.out.println("del="+map);
        Result result = new Result();
        result.setCode("1");
        result.setData(Collections.singletonList(shopInfoService.del(map)));
        return  JSON .toJSONString(result);
    }

}
